package test_new;

public class Matrix<T> {
	T[][] array;
	public Matrix(T[][] array) {
		this.array = array; 
	}
	public T[][] getArray(){
		return array;
	}
	public void rotateInPlace(){
		for (int i = 0; i < Math.abs(array.length/2); i++) {
			for(int j = i; j < array.length-1-i; j++) {
				T resultTemp = array[i][j];
				array[i][j] = array[array.length-1-j][i];
				array[array.length-1-j][i] = array[array.length-1-i][array.length-1-j];
				array[array.length-1-i][array.length-1-j] = array[j][array.length-1-i];
				array[j][array.length-1-i] = resultTemp;
			}
		}
		
	}
	public void transposeInPlace(){
		for (int i = 0; i < array.length; i++) {
			for(int j = i; j < array.length; j++) {
				swap(i, j, j, i);
			}
		}
	}
	
	private void swap(int i1, int j1, int i2, int j2){
		T temp = array[i1][j1];
		array[i1][j1] = array[i2][j2];
		array[i2][j2] = temp;
	}
}
